package com.canyou.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 树节点模型(非线程安全)
 *
 * @author fy
 * @date 2018-08-02 16:01
 */
@Data
@ApiModel(value = "AbstractTreeNode", description = "通用树节点模型")
public abstract class AbstractTreeNode<T extends AbstractTreeNode> implements Serializable {

    private static final long serialVersionUID = 667031968138837645L;

    /**
     * 节点id
     */
    @ApiModelProperty("节点id")
    protected Long id;

    /**
     * 父节点id
     */
    @ApiModelProperty("父节点id")
    protected Long parentId;

    /**
     * 子节点集合
     */
    @ApiModelProperty("子节点集合")
    protected List<T> children;

    /**
     * 增加子节点
     *
     * @param node
     */
    public void addChildren(T node) {
        if (children == null) {
            children = new ArrayList<>();
        }
        children.add(node);
    }

}
